home *** CD-ROM | disk | FTP | other *** search
- /*
- File: CRecordID.h
-
- Contains: Copied and modified from Admin sources
-
- Written by: Tim Harnett
-
- Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <9> 2/27/95 TMH adapt to use ETO16 universal headers
- <8> 2/21/95 TMH metrowerks changes don't use duplicate arg name
- <7> 2/17/95 TMH added CRecordID(short pcatDSRefNum,StringPtr recName,StringPtr
- recType)
- <6> 2/14/95 CL remove globls
- <5> 10/18/94 TMH added PackKeyChainRID
- <4> 10/14/94 TMH added CRLI constructor
- <3> 10/13/94 TMH added GetDiscriminator etc.
- <2> 10/11/94 TMH added CRecordID(short pcatDSRefNum,char* recName,char* recType)
- <1> 9/20/94 TMH Abandon RoadsideRest embrace Mercury
- <2> 6/14/94 TMH added RecordID* rid assignment operator
- 4/5/94 TMH xxx put comment here xxx
-
- To Do:
- */
-
-
- #ifndef __CRecordID__
- #define __CRecordID__
-
-
- #ifndef __BaseTypes__
- #include "BaseTypes.h"
- #endif
-
- #ifndef __CRString__
- #include "CRString.h"
- #endif
-
-
-
- //------------------------------------------
- // C R L I
- //--------------------------------------------
-
-
- class CRLI {
- public:
- CDirectoryName* fDirName;
- DirDiscriminator fDiscriminator;
- DNodeNum fDNodeNumber;
- PackedPathNamePtr fPackedPath;
-
- CRLI(char* dirName,OSType signature, long dirMisc= 0);
- CRLI(StringPtr dirName,OSType signature, long dirMisc= 0);
- CRLI(CDirectoryName& dirName,DirDiscriminator& dirDisc);
- private:
- void Initialize();
-
- CDirectoryName _fDirName;
- };
-
- inline void CRLI::Initialize()
- {
- memset(this,0,sizeof(CRLI));
- fDirName = &_fDirName;
- }
-
- inline CRLI::CRLI(CDirectoryName& dirName,DirDiscriminator& dirDisc)
- {
- this->Initialize();
-
- _fDirName = dirName;
- fDiscriminator.signature = dirDisc.signature;
- fDiscriminator.misc = dirDisc.misc;
- }
-
- inline CRLI::CRLI(char* dirName,OCEDirectoryKind signature, long dirMisc)
- {
- this->Initialize();
-
- _fDirName = dirName;
-
- fDiscriminator.signature = signature;
- fDiscriminator.misc = dirMisc;
-
-
- }
-
- inline CRLI::CRLI(StringPtr dirName,OCEDirectoryKind signature, long dirMisc)
- {
- this->Initialize();
- _fDirName = dirName;
-
- fDiscriminator.signature = signature;
- fDiscriminator.misc = dirMisc;
- }
-
-
- //------------------------------------------------------------------------
- // C P a c k e d R L I
- //-------------------------------------------------------------------------
-
-
- // DO NOT USE FOR PATHNAMES RLI FORM!!!
- // Implements ONLY The dnode number form.
- //
- //
- // Personal Catalog Note: Because a record can be references with only
- // a dsRefNum; a full RLI is not neccessary. The PCAT form hold only the
- // dsRefNum.
- //
- // TBD: some accessors. PCAT RLI's are not supported.
- //
- //----------------------------------------------------------------------------
-
- class CPackedRLI {
- friend class CRecordID;
- public:
-
- unsigned short fLength; // length of the packed RLI excluding length field
- DNodeNum fNodeNumber; // dNodeNumber of the cluster
- CDirectoryName fDirectoryName; // var length
- DirDiscriminator fDiscriminator; // packed after the fDirName.
- short fPackedPathNameLen;
-
- private:
- short fDSRefNum; //
-
- public:
- CPackedRLI() {fDSRefNum = 0;};
- CPackedRLI& operator =(RLI* rli);
- CPackedRLI& operator =(CRLI& rli);
-
-
- // So we do assignment to OCE.h defined fields.
- operator PackedRLI*() { return (PackedRLI*) this; };
- operator const PackedRLI*() const { return (const PackedRLI*) this; };
-
- // Accessors
- short GetDSRefNum() {return fDSRefNum;};
- DirDiscriminator GetDiscriminator() { long offset = fDirectoryName.Length(); offset+=offset&1; return *(DirDiscriminator*)((char*)&fDirectoryName + offset); }
- OSType GetDirSignature() { DirDiscriminator dirDisc = this->GetDiscriminator(); return dirDisc.signature; }
-
- };
-
- inline CPackedRLI& CPackedRLI::operator =(RLI* theRLI) { OCEPackRLI(theRLI, *this, sizeof(CPackedRLI)); fDSRefNum = 0; return *this;};
-
- //------------------------------------------
- // C R e c o r d I D
- //--------------------------------------------
-
- // !!!!CAUTION!!!! : A CRecordID is binary compatable with the OCE defined RecordID structure.
- // A pointer to one of these can be use anywhere a RecordIDPtr is called for in
- // OCE API. However be aware of the DANGER of casting RecordID's to be CRecordID's.
- // The class assumes that fName and fType pointers point to buffers sufficient
- // to hold the longest name or type allowed. For example this means if you have
- // a RecordID that points into a packed DSSpec the you should not call SetName().
- // Also note that the node number format of the RLI is assumed.
-
-
- // The key chain likes packed rids small.... we humor it.
- #define kKeyChainPackedRIDSize 20
- typedef unsigned char KeyChainPackedRID[kKeyChainPackedRIDSize], *KeyChainPackedRIDPtr;
-
-
- class CRecordID {
- public:
- CPackedRLI* fRLI;
- CreationID fCID;
- CRecordName* fName;
- CRecordType* fType;
-
- // space for these.
- private:
- CPackedRLI _fPackedRLI;
- CRecordName _fRecordName;
- CRecordType _fRecordType;
-
- public:
-
- // Constructors
- CRecordID();
-
- CRecordID(short dsRefNum, CreationID cid);
- CRecordID(short pcatDSRefNum,char* recName,char* recType);
- CRecordID(short pcatDSRefNum,StringPtr recName,StringPtr recType);
-
- CRecordID(CRLI& rli,CRecordName& recordName,CRecordType& recordType);
-
- CRecordID(CRecordID& cRID);
- CRecordID(PackedDSSpecPtr packedDSSpec);
- CRecordID(short dsRefNum, PackedRecordID* packedRecordID);
-
-
- // Assignment Operators
- CRecordID& operator =(CRecordID& cRID);
- CRecordID& operator =(RecordID* rid);
- CRecordID& operator =(PackedDSSpecPtr packedDSSpec) { this->SetFromPackedDSSpec(packedDSSpec); return *this; };
-
- void SetName(CRecordName& newName);
- void SetName(StringPtr newName);
- void SetType(short);
- void SetNodeNumber(long nodeNumber) { fRLI->fNodeNumber = nodeNumber; };
-
- PackedDSSpec** PackDSSpec();
-
- KeyChainPackedRIDPtr PackKeyChainRID(KeyChainPackedRIDPtr pRID);
-
-
- // Cast Operators
- operator RecordID*() { return (RecordID*) this; };
- operator const RecordID*() const { return (const RecordID*) this; };
-
-
- // Accessors
- CRecordName& Name() { return _fRecordName; }
- DNodeNum Node() { return fRLI->fNodeNumber; };
- AddrBlock GetServerHint() { AddrBlock nilAddrBlock = {0,0,0}; return nilAddrBlock;} ;
- short GetDSRefNum() {return _fPackedRLI.GetDSRefNum();};
-
- CDirectoryName& DirName() { return _fPackedRLI.fDirectoryName; }
- OSType DirectorySignature() { return _fPackedRLI.fDiscriminator.signature; };
-
- void SetFromPackedDSSpec(PackedDSSpecPtr packedDSSpec);
-
-
- OSErr GetNameAndType();
- OSErr SetNameAndType( Boolean allowDups );
- OSErr Create(Boolean allowDuplicates=false);
- OSErr CreateAsAlias(CRecordID& origRID,Boolean allowDuplicate=false,long backPtrFlags = 0);
- OSErr Delete();
-
- OSErr AddAsPseudoNym(Boolean allowDupliate=false); // assumes pseudonym have same Type as record.
- OSErr DeletePseudoNym(); // assumes pseudonym have same Type as record.
-
- private:
- void Initialize();
-
- };
-
-
- inline void CRecordID::SetType(short recTypeIndex) { _fRecordType = (RString*) OCEGetIndRecordType(recTypeIndex); fCID.source = 0; fCID.seq = 0;};
-
-
- inline void CRecordID::SetName(CRecordName& newName) { *fName = newName; };
- inline void CRecordID::SetName(StringPtr newName) { *fName = newName; };
- inline CRecordID::CRecordID()
- {
- this->Initialize();
- };
-
-
-
- #endif __CRecordID__
-